/**
 * 
 */
package com.et114.test.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.et114.components.ectable.EXTableUtils;
import com.et114.components.simpletable.DataList;
import com.et114.core.action.BaseDispatchAction;
import com.et114.test.dao.TestVO;
import com.et114.test.services.TestBean;


import java.util.List;

/**
 * @author guanhw
 *
 */
public class EctableDispAction extends BaseDispatchAction {
	/**
	 * Method loads
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward loads( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response ) throws Exception {
			TestVO vo = new TestVO () ;
			TestBean bean = ( TestBean ) getBean( "testBean" ) ;
			int lr = bean.loadAllRows(  vo  ) ;
			EXTableUtils.initLimitPage(  vo , lr ,  request ) ;
			logger.info(  vo.getPageNum() + ":" + vo.getPageSize() + ":" + vo.getCalculate() ) ;
			List list = bean.loadTests( vo ) ;
			request.setAttribute(  "list" , list ) ;
			return mapping.findForward(  "ectable"  ) ;
	}
	
	/**
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 */
	public ActionForward loadSimpleTable( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response ) throws Exception  {
			String spageNum = request.getParameter(  "pageNum"  );
			int pageNum = 1 ; 
			if ( spageNum != null && !"".equals(  spageNum   ) )  pageNum = Integer.parseInt(  spageNum  ) ;
			TestVO vo = new TestVO () ;
			vo.setPageSize(  5  ) ;
			vo.setPageNum(   pageNum  ) ;
			TestBean bean = ( TestBean ) getBean( "testBean" ) ;

			DataList dl = bean.loadTestDataList(  vo  ) ; 
			request.setAttribute(  "dl" , dl ) ;
			return mapping.findForward(  "simpletable"  ) ;
	}	
	/**
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward checkToken( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response ) throws Exception  {
		TestBean bean = ( TestBean ) getBean( "testBean" ) ;
		TestVO vo = new TestVO () ;
		vo.setName( "ghw"  ) ;		
		bean.saveTest ( vo );
		return mapping.findForward(  "index"  ) ;
	}
	
	public ActionForward saveToken( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response ) throws Exception  {
		return mapping.findForward(  "token"  ) ;
	}	
}
